<?php

namespace app\http\api\controller;

use app\repository\dao\api\OrderDao;
use Carbon\Carbon;
use support\Cache;
use support\Response;
use Webman\Http\Request;

/**
 * @desc    档口订单控制器
 * @author  OverMiracle
 * @date    2024-02-07
 */
class Order
{

    public function index(Request $request): Response
    {
        $today = Carbon::today();
        $data = [
            'receipt_date_begin' => $request->post('receipt_date_begin', $today->format('Y-m-d 00:00:00')),
            'receipt_date_end' => $request->post('receipt_date_end', $today->format('Y-m-d 23:59:59')),
            // 0 支付，1 退款 2全部
            'genre' => $request->post('genre', 2),
            'start' => $request->post('start', 0),
            'length' => $request->post('length', 10),
            'mode_id' => $request->post('mode_id'),
            'merchant_id' => $request->post('merchant_id'),
            'sales_num' => $request->post('sales_num'),
            'client_code' => $request->post('client_code'),
            'assistant_id' => $request->post('assistant_id'),
            'orgz_id' => $request->post('orgz_id'),
        ];

        $key = 'order_list@' . md5(json_encode($data, 256));
        $result = Cache::get($key);
        if ($result == null) {
            $result = OrderDao::getList($data);
            Cache::set($key, $result, 1800);
        }
        return json([
            'code' => 0,
            'msg' => '获取订单流水成功',
            'service_name' => null,
            'data' => $result['list'],
            'total' => $result['total'],
        ]);
    }
}